﻿using Abp.EntityFramework;
using Laboratory.Entities.User;
using Laboratory.EntityFramework;
using Laboratory.EntityFramework.Repositories;
using Laboratory.IRepositories.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace Laboratory.Repositories.User
{
    public class AccountRepository : LaboratoryRepositoryBase<Account, Guid>, IAccountRepository
    {
        public AccountRepository(IDbContextProvider<LaboratoryDbContext> dbContextProvider) : base(dbContextProvider)
        {

        }

        /// <summary>
        /// 验证名称是否存在
        /// </summary>
        /// <param name="id">Id</param>
        /// <param name="name">名称</param>
        /// <param name="loginId">登录Id</param>
        /// <returns></returns>
        public bool ExistsName(Guid? id, string name,string loginId)
        {
            Expression<Func<Account, bool>> condition =
                x => (id == null || x.Id != id) &&
                (x.Name == name || x.LoginId == loginId);

            Account entity = this.FirstOrDefault(condition);

            return entity != null;
        }


    }
}
